﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:APP_REGINFO
	/// </summary>
	public partial class APP_REGINFO : BaseDAL<GSLMS.Entity.TB_APP_REGINFO>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public APP_REGINFO()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_APP_REGINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_LINKMAN", model.LINKMAN),
								new OracleParameter("P_LINKMANTEL", model.LINKMANTEL),
								new OracleParameter("P_SOURCE", model.SOURCE),
								new OracleParameter("P_SALESMANID", model.SALESMANID),
								new OracleParameter("P_SALESMAN", model.SALESMAN),
								new OracleParameter("P_MEDIATORID", model.MEDIATORID),
								new OracleParameter("P_MEDIATOR", model.MEDIATOR),
								new OracleParameter("P_FIELDPROJECT", model.FIELDPROJECT),
								new OracleParameter("P_BUSSTYPE", model.BUSSTYPE),
								new OracleParameter("P_PRODUCTID", model.PRODUCTID),
								new OracleParameter("P_PRODUCTNAME", model.PRODUCTNAME),
								new OracleParameter("P_LOANPHASE", model.LOANPHASE),
								new OracleParameter("P_LOANPHASETYPE", model.LOANPHASETYPE),
								new OracleParameter("P_REGDATE", model.REGDATE),
								new OracleParameter("P_REGMAN", model.REGMAN),
								new OracleParameter("P_INTEMTIONAMT", model.INTEMTIONAMT),
								new OracleParameter("P_IMPORTANTLEVEL", model.IMPORTANTLEVEL),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_LASTFLOWDATE", model.LASTFLOWDATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_ISSYSTEMSTOP", model.ISSYSTEMSTOP),
								new OracleParameter("P_STOPBY", model.STOPBY),
								new OracleParameter("P_STOPDATE", model.STOPDATE),
								new OracleParameter("P_DEPID", model.DEPID),
								new OracleParameter("P_DEPNAME", model.DEPNAME),
								new OracleParameter("P_SYSTEMID", model.SYSTEMID),
								new OracleParameter("P_MODIFYBY", model.MODIFYBY),
								new OracleParameter("P_MODIFYDATE", model.MODIFYDATE),
								new OracleParameter("P_DELETEFLAG", model.DELETEFLAG),
								new OracleParameter("P_DELETEBY", model.DELETEBY),
								new OracleParameter("P_DELETEDATE", model.DELETEDATE),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 37; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_reginfo_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_APP_REGINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_LINKMAN", model.LINKMAN),
								new OracleParameter("P_LINKMANTEL", model.LINKMANTEL),
								new OracleParameter("P_SOURCE", model.SOURCE),
								new OracleParameter("P_SALESMANID", model.SALESMANID),
								new OracleParameter("P_SALESMAN", model.SALESMAN),
								new OracleParameter("P_MEDIATORID", model.MEDIATORID),
								new OracleParameter("P_MEDIATOR", model.MEDIATOR),
								new OracleParameter("P_FIELDPROJECT", model.FIELDPROJECT),
								new OracleParameter("P_BUSSTYPE", model.BUSSTYPE),
								new OracleParameter("P_PRODUCTID", model.PRODUCTID),
								new OracleParameter("P_PRODUCTNAME", model.PRODUCTNAME),
								new OracleParameter("P_LOANPHASE", model.LOANPHASE),
								new OracleParameter("P_LOANPHASETYPE", model.LOANPHASETYPE),
								new OracleParameter("P_REGDATE", model.REGDATE),
								new OracleParameter("P_REGMAN", model.REGMAN),
								new OracleParameter("P_INTEMTIONAMT", model.INTEMTIONAMT),
								new OracleParameter("P_IMPORTANTLEVEL", model.IMPORTANTLEVEL),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_LASTFLOWDATE", model.LASTFLOWDATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_ISSYSTEMSTOP", model.ISSYSTEMSTOP),
								new OracleParameter("P_STOPBY", model.STOPBY),
								new OracleParameter("P_STOPDATE", model.STOPDATE),
								new OracleParameter("P_DEPID", model.DEPID),
								new OracleParameter("P_DEPNAME", model.DEPNAME),
								new OracleParameter("P_SYSTEMID", model.SYSTEMID),
								new OracleParameter("P_MODIFYBY", model.MODIFYBY),
								new OracleParameter("P_MODIFYDATE", model.MODIFYDATE),
								new OracleParameter("P_DELETEFLAG", model.DELETEFLAG),
								new OracleParameter("P_DELETEBY", model.DELETEBY),
								new OracleParameter("P_DELETEDATE", model.DELETEDATE),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 37; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_reginfo_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_reginfo_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

        /// <summary>
        /// 判断是否存在特批申请，0表示不存在；大于0表示存在，并返回值为特批申请的记录ID
        /// </summary>
        /// <param name="regInfoID">申请登记记录ID</param>
        /// <returns></returns>
        public long IsSpecialExists(long regInfoID)
        {
            long specialInfoID = 0;

            OracleParameter[] parms = new OracleParameter[]{
								new OracleParameter("p_reginfoid", regInfoID),
                                new OracleParameter("p_specialinfoid", OracleType.Number)
                };

            parms[0].Direction = ParameterDirection.Input;
            parms[1].Direction = ParameterDirection.Output;

            OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_isSpecialExists", parms);

            if (parms[1].Value != DBNull.Value)
                specialInfoID = OracleHelper.ToLong(parms[1].Value.ToString());

            

            return specialInfoID;
        }


		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_APP_REGINFO DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_APP_REGINFO model = new GSLMS.Entity.TB_APP_REGINFO();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["CUSTNAME"]!=null && dr["CUSTNAME"].ToString()!="")
				{
					model.CUSTNAME=dr["CUSTNAME"].ToString();
				}
				if(dr["CUSTNO"]!=null && dr["CUSTNO"].ToString()!="")
				{
					model.CUSTNO=dr["CUSTNO"].ToString();
				}
				if(dr["LINKMAN"]!=null && dr["LINKMAN"].ToString()!="")
				{
					model.LINKMAN=dr["LINKMAN"].ToString();
				}
				if(dr["LINKMANTEL"]!=null && dr["LINKMANTEL"].ToString()!="")
				{
					model.LINKMANTEL=dr["LINKMANTEL"].ToString();
				}
				if(dr["SOURCE"]!=null && dr["SOURCE"].ToString()!="")
				{
					model.SOURCE=dr["SOURCE"].ToString();
				}
				if(dr["SALESMANID"]!=null && dr["SALESMANID"].ToString()!="")
				{
					model.SALESMANID=OracleHelper.ToLong(dr["SALESMANID"].ToString());
				}
				if(dr["SALESMAN"]!=null && dr["SALESMAN"].ToString()!="")
				{
					model.SALESMAN=dr["SALESMAN"].ToString();
				}
				if(dr["MEDIATORID"]!=null && dr["MEDIATORID"].ToString()!="")
				{
					model.MEDIATORID=OracleHelper.ToLong(dr["MEDIATORID"].ToString());
				}
				if(dr["MEDIATOR"]!=null && dr["MEDIATOR"].ToString()!="")
				{
					model.MEDIATOR=dr["MEDIATOR"].ToString();
				}
				if(dr["FIELDPROJECT"]!=null && dr["FIELDPROJECT"].ToString()!="")
				{
                    model.FIELDPROJECT = OracleHelper.ToInt(dr["FIELDPROJECT"].ToString());
				}
				if(dr["BUSSTYPE"]!=null && dr["BUSSTYPE"].ToString()!="")
				{
                    model.BUSSTYPE = OracleHelper.ToInt(dr["BUSSTYPE"].ToString());
				}
				if(dr["PRODUCTID"]!=null && dr["PRODUCTID"].ToString()!="")
				{
					model.PRODUCTID=OracleHelper.ToLong(dr["PRODUCTID"].ToString());
				}
				if(dr["PRODUCTNAME"]!=null && dr["PRODUCTNAME"].ToString()!="")
				{
					model.PRODUCTNAME=dr["PRODUCTNAME"].ToString();
				}
				if(dr["LOANPHASE"]!=null && dr["LOANPHASE"].ToString()!="")
				{
                    model.LOANPHASE = OracleHelper.ToInt(dr["LOANPHASE"].ToString());
				}
				if(dr["LOANPHASETYPE"]!=null && dr["LOANPHASETYPE"].ToString()!="")
				{
                    model.LOANPHASETYPE = OracleHelper.ToInt(dr["LOANPHASETYPE"].ToString());
				}
				if(dr["REGDATE"]!=null && dr["REGDATE"].ToString()!="")
				{
					model.REGDATE=DateTime.Parse(dr["REGDATE"].ToString());
				}
				if(dr["REGMAN"]!=null && dr["REGMAN"].ToString()!="")
				{
					model.REGMAN=dr["REGMAN"].ToString();
				}
				if(dr["INTEMTIONAMT"]!=null && dr["INTEMTIONAMT"].ToString()!="")
				{
					model.INTEMTIONAMT=OracleHelper.ToDecimal(dr["INTEMTIONAMT"].ToString());
				}
				if(dr["IMPORTANTLEVEL"]!=null && dr["IMPORTANTLEVEL"].ToString()!="")
				{
					model.IMPORTANTLEVEL=dr["IMPORTANTLEVEL"].ToString();
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				if(dr["LASTFLOWDATE"]!=null && dr["LASTFLOWDATE"].ToString()!="")
				{
					model.LASTFLOWDATE=DateTime.Parse(dr["LASTFLOWDATE"].ToString());
				}
				if(dr["STATUS"]!=null && dr["STATUS"].ToString()!="")
				{
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
				}
				if(dr["ISSYSTEMSTOP"]!=null && dr["ISSYSTEMSTOP"].ToString()!="")
				{
                    model.ISSYSTEMSTOP = OracleHelper.ToInt(dr["ISSYSTEMSTOP"].ToString());
				}
				if(dr["STOPBY"]!=null && dr["STOPBY"].ToString()!="")
				{
					model.STOPBY=dr["STOPBY"].ToString();
				}
				if(dr["STOPDATE"]!=null && dr["STOPDATE"].ToString()!="")
				{
					model.STOPDATE=DateTime.Parse(dr["STOPDATE"].ToString());
				}
				if(dr["DEPID"]!=null && dr["DEPID"].ToString()!="")
				{
					model.DEPID=OracleHelper.ToLong(dr["DEPID"].ToString());
				}
				if(dr["DEPNAME"]!=null && dr["DEPNAME"].ToString()!="")
				{
					model.DEPNAME=dr["DEPNAME"].ToString();
				}
				if(dr["SYSTEMID"]!=null && dr["SYSTEMID"].ToString()!="")
				{
                    model.SYSTEMID = OracleHelper.ToInt(dr["SYSTEMID"].ToString());
				}
				if(dr["MODIFYBY"]!=null && dr["MODIFYBY"].ToString()!="")
				{
					model.MODIFYBY=dr["MODIFYBY"].ToString();
				}
				if(dr["MODIFYDATE"]!=null && dr["MODIFYDATE"].ToString()!="")
				{
					model.MODIFYDATE=DateTime.Parse(dr["MODIFYDATE"].ToString());
				}
				if(dr["DELETEFLAG"]!=null && dr["DELETEFLAG"].ToString()!="")
				{
                    model.DELETEFLAG = OracleHelper.ToInt(dr["DELETEFLAG"].ToString());
				}
				if(dr["DELETEBY"]!=null && dr["DELETEBY"].ToString()!="")
				{
					model.DELETEBY=dr["DELETEBY"].ToString();
				}
				if(dr["DELETEDATE"]!=null && dr["DELETEDATE"].ToString()!="")
				{
					model.DELETEDATE=DateTime.Parse(dr["DELETEDATE"].ToString());
				}
				if(dr["SPAREFIELD1"]!=null && dr["SPAREFIELD1"].ToString()!="")
				{
                    model.SPAREFIELD1 = OracleHelper.ToInt(dr["SPAREFIELD1"].ToString());
				}
				if(dr["SPAREFIELD2"]!=null && dr["SPAREFIELD2"].ToString()!="")
				{
					model.SPAREFIELD2=dr["SPAREFIELD2"].ToString();
				}
				if(dr["SPAREFIELD3"]!=null && dr["SPAREFIELD3"].ToString()!="")
				{
					model.SPAREFIELD3=dr["SPAREFIELD3"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

        /// <summary>
        ///DataRowToModel 
        /// </summary>
        private GSLMS.Entity.TB_APP_REFREGINFO DataRowToRefRegInfoModel(DataRow dr)
        {
            if (dr != null && dr.ItemArray.Length > 0)
            {
                GSLMS.Entity.TB_APP_REFREGINFO model = new GSLMS.Entity.TB_APP_REFREGINFO();
                if (dr["ID"] != null && dr["ID"].ToString() != "")
                {
                    model.ID = OracleHelper.ToLong(dr["ID"].ToString());
                }
                if (dr["REGINFOID"] != null && dr["REGINFOID"].ToString() != "")
                {
                    model.REGINFOID = OracleHelper.ToLong(dr["REGINFOID"].ToString());
                }
                if (dr["CUSTNAME"] != null && dr["CUSTNAME"].ToString() != "")
                {
                    model.CUSTNAME = dr["CUSTNAME"].ToString();
                }
                if (dr["REFBY"] != null && dr["REFBY"].ToString() != "")
                {
                    model.REFBY = dr["REFBY"].ToString();
                }
                if (dr["REFBYNAME"] != null && dr["REFBYNAME"].ToString() != "")
                {
                    model.REFBYNAME = dr["REFBYNAME"].ToString();
                }
                if (dr["APPDATE"] != null && dr["APPDATE"].ToString() != "")
                {
                    model.APPDATE = DateTime.Parse(dr["APPDATE"].ToString());
                }
                if (dr["OUTDEPID"] != null && dr["OUTDEPID"].ToString() != "")
                {
                    model.OUTDEPID = OracleHelper.ToLong(dr["OUTDEPID"].ToString());
                }
                if (dr["OUTDEPNAME"] != null && dr["OUTDEPNAME"].ToString() != "")
                {
                    model.OUTDEPNAME = dr["OUTDEPNAME"].ToString();
                }
                if (dr["OUTTIME"] != null && dr["OUTTIME"].ToString() != "")
                {
                    model.OUTTIME = DateTime.Parse(dr["OUTTIME"].ToString());
                }
                if (dr["INDEPID"] != null && dr["INDEPID"].ToString() != "")
                {
                    model.INDEPID = OracleHelper.ToLong(dr["INDEPID"].ToString());
                }
                if (dr["INDEPNAME"] != null && dr["INDEPNAME"].ToString() != "")
                {
                    model.INDEPNAME = dr["INDEPNAME"].ToString();
                }
                if (dr["INTIME"] != null && dr["INTIME"].ToString() != "")
                {
                    model.INTIME = DateTime.Parse(dr["INTIME"].ToString());
                }
                if (dr["SALESMANID"] != null && dr["SALESMANID"].ToString() != "")
                {
                    model.SALESMANID = OracleHelper.ToLong(dr["SALESMANID"].ToString());
                }
                if (dr["SALESMAN"] != null && dr["SALESMAN"].ToString() != "")
                {
                    model.SALESMAN = dr["SALESMAN"].ToString();
                }
                if (dr["DETAIL"] != null && dr["DETAIL"].ToString() != "")
                {
                    model.DETAIL = dr["DETAIL"].ToString();
                }
                if (dr["STATUS"] != null && dr["STATUS"].ToString() != "")
                {
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
                }
                if (dr["AUDITBY"] != null && dr["AUDITBY"].ToString() != "")
                {
                    model.AUDITBY = dr["AUDITBY"].ToString();
                }
                if (dr["AUDITTIME"] != null && dr["AUDITTIME"].ToString() != "")
                {
                    model.AUDITTIME = DateTime.Parse(dr["AUDITTIME"].ToString());
                }
                if (dr["BACKSTATUS"] != null && dr["BACKSTATUS"].ToString() != "")
                {
                    model.BACKSTATUS = OracleHelper.ToInt(dr["BACKSTATUS"].ToString());
                }
                if (dr["SPAREFIELD1"] != null && dr["SPAREFIELD1"].ToString() != "")
                {
                    model.SPAREFIELD1 = OracleHelper.ToInt(dr["SPAREFIELD1"].ToString());
                }
                if (dr["SPAREFIELD2"] != null && dr["SPAREFIELD2"].ToString() != "")
                {
                    model.SPAREFIELD2 = dr["SPAREFIELD2"].ToString();
                }
                if (dr["SPAREFIELD3"] != null && dr["SPAREFIELD3"].ToString() != "")
                {
                    model.SPAREFIELD3 = dr["SPAREFIELD3"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_APP_REGINFO GetByID(long ID)
		{
			GSLMS.Entity.TB_APP_REGINFO sModel = new GSLMS.Entity.TB_APP_REGINFO();
            APP_LOGINFO logDal = new APP_LOGINFO();
            DataTable logDt = null;


            OracleParameter[] parms = new OracleParameter[] { 
              new OracleParameter("p_id",ID),
              new OracleParameter("p_cur",OracleType.Cursor),
              new OracleParameter("p_logcur",OracleType.Cursor)
            };

            parms[0].Direction = ParameterDirection.Input;
            parms[1].Direction = ParameterDirection.Output;
            parms[2].Direction = ParameterDirection.Output;
           
            DataSet ds = OracleHelper.ExecuteDataset(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_reginfo_get", parms);

			
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);

                if (ds.Tables.Count > 1)
                    logDt = ds.Tables[1];

                if (logDt != null)
                {
                    var logList = new List<GSLMS.Entity.TB_APP_LOGINFO>();
                    
                    for (int i = 0; i < logDt.Rows.Count; i++)
                    {
                        GSLMS.Entity.TB_APP_LOGINFO model = new GSLMS.Entity.TB_APP_LOGINFO();
                        model = logDal.DataRowToModel(logDt.Rows[i]);
                        logList.Add(model);
                    }

                    sModel.LogInfoList = logList;
                }
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_APP_REGINFO> GetList(GSLMS.Entity.TB_APP_REGINFO searchParam)
		{
			var list=new List<GSLMS.Entity.TB_APP_REGINFO>();
			DataTable dt = null;
			string tblName = "TB_APP_REGINFO";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;

                // 客户名称
                //手机
                //业务员
                //登记时间从
                //至
                //状态

            //是否计算总数
            countFlag = (searchParam.Pagination.ReCount != null && searchParam.Pagination.ReCount) ? 1 : 0;
            pageSize = (searchParam.Pagination.PageSize > 0 || searchParam.Pagination.PageSize==-1) ? searchParam.Pagination.PageSize : 15;
            pageIndex = (searchParam.Pagination.CurrentIndex != null && searchParam.Pagination.CurrentIndex > 0) ? searchParam.Pagination.CurrentIndex : 1;
            
            strSort = searchParam.StrSort;
            
            if (searchParam.CUSTNAME!=null&&searchParam.CUSTNAME.Trim() != "")
            {
                sqlWhere += " and custname like '%"+OracleHelper.ReplaceUnsafeSql(searchParam.CUSTNAME.Trim())+"%'";
            }

            if (searchParam.LINKMANTEL!=null&&searchParam.LINKMANTEL.Trim() != "")
            {
                sqlWhere += " and linkmantel like '%" + OracleHelper.ReplaceUnsafeSql(searchParam.LINKMANTEL.Trim()) + "%'";
            }

            if (searchParam.SALESMANID!=null&&searchParam.SALESMANID>0)
            {
                sqlWhere += " and SALESMANID=" +searchParam.SALESMANID.ToString();
            }

            if (searchParam.STATUS!=null&&searchParam.STATUS > 0)
            {
                  sqlWhere += " and status=" + searchParam.STATUS.ToString();
            }

            if (searchParam.REGDATE != null && searchParam.REGDATE.ToString().Trim() != "")
            {
                sqlWhere += " and RegDate>=to_date('" + Convert.ToDateTime(searchParam.REGDATE).ToString("yyyy-MM-dd HH:mm:ss") + "','yyyy-mm-dd hh24:mi:ss')";
            }

            if (searchParam.REGDATE_END != null && searchParam.REGDATE_END.ToString().Trim() != "")
            {
                sqlWhere += " and RegDate<to_date('" + Convert.ToDateTime(searchParam.REGDATE_END).AddDays(1).AddSeconds(-1).ToString("yyyy-MM-dd HH:mm:ss") + "','yyyy-mm-dd hh24:mi:ss')";
            }

            //业务种类
            if (searchParam.BUSSTYPE != null && searchParam.BUSSTYPE > 0)
            {
                if (searchParam.BUSSTYPE == 99)
                    sqlWhere += " and busstype<>3";
                else
                    sqlWhere += " and busstype="+searchParam.BUSSTYPE.ToString();
            }



			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
            if (searchParam.Pagination.ReCount)
            {
                searchParam.RowCount = totalCount;
                searchParam.Pagination.RowCount = totalCount;
            }
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_APP_REGINFO model = new GSLMS.Entity.TB_APP_REGINFO();
					model = DataRowToModel(dt.Rows[i]);
                    
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

        /// <summary>
        /// 判断客户名称是否已经存在,0不用提示，1提示：'客户名称与原有客户名称重复，是否确认保存',2提示：'此客户名称存在未完结的项目，不能登记申请'
        /// </summary>
        /// <param name="regID"></param>
        /// <param name="custNO"></param>
        /// <param name="systemID"></param>
        /// <returns></returns>
        public int isCustExits(long regID, string custNO, int systemID)
        {
            int num = 0;

            OracleParameter[] parms = new OracleParameter[]{
								new OracleParameter("p_reginfoid", regID),
                                new OracleParameter("p_custno",custNO),
                                new OracleParameter("P_SYSTEMID",systemID),
                                new OracleParameter("returnvalue",OracleType.Int32)
            };

            parms[0].Direction = ParameterDirection.Input;
            parms[1].Direction = ParameterDirection.Input;
            parms[2].Direction = ParameterDirection.Input;
            parms[3].Direction = ParameterDirection.Output;

            OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_reginfo_chk", parms);
            if (parms[3].Value != DBNull.Value)
                num = OracleHelper.ToInt(parms[3].Value.ToString());

            return num;
        }


       
        /// <summary>
        /// 提取客户信息,通过DataType数据类型获取不同的客户信息,并需要把证件号码传入
        /// </summary>
        /// <param name="searchParam"></param>
        /// <returns></returns>
        public  List<GSLMS.Entity.TB_APP_REGINFO> GetCustList(GSLMS.Entity.TB_APP_REGINFO searchParam)
        {
            var list = new List<GSLMS.Entity.TB_APP_REGINFO>();

            return list;
        }


        /// <summary>
        /// 通过转介申请记录ID提取申请登记信息
        /// </summary>
        /// <param name="refID">转介申请记录ID</param>
        /// <returns></returns>
        public GSLMS.Entity.TB_APP_REGINFO GetByRefID(long refID)
        {
            var model = new GSLMS.Entity.TB_APP_REGINFO();

            OracleParameter[] parms = new OracleParameter[] {
              new OracleParameter("p_refid",refID),
              new OracleParameter("p_cur",OracleType.Cursor),
              new OracleParameter("p_rcur",OracleType.Cursor),
            };

            parms[0].Direction = ParameterDirection.Input;
            parms[1].Direction = ParameterDirection.Output;
            parms[2].Direction = ParameterDirection.Output;

            DataSet ds = OracleHelper.ExecuteDataset(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_reginfo_getbyrefid", parms);
            if (ds != null && ds.Tables.Count > 0&&ds.Tables[0].Rows.Count>0)
            {
                model = DataRowToModel(ds.Tables[0].Rows[0]);

                var refModel = new GSLMS.Entity.TB_APP_REFREGINFO();
                if (ds.Tables.Count > 1&&ds.Tables[1].Rows.Count>0)
                {
                    refModel = DataRowToRefRegInfoModel(ds.Tables[1].Rows[0]);
                }

                model.RefRegInfo = refModel;

            }

            return model;
        
        }





		#endregion  Method
	}
}

